package com.niiwoo.civet.trade.listener;

import java.io.IOException;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.niiwoo.civet.trade.constant.RabbitConstant;
import com.niiwoo.civet.trade.service.local.intelligenceInvest.IntelligenceInvestService;
import com.rabbitmq.client.Channel;

import lombok.extern.slf4j.Slf4j;

/**
 * 智能投投资结果通知
 * 
 * @author liuchun
 *
 *         2018年11月16日
 */
@Slf4j
@Component
public class IntelligenceInvestEndEventListener {
	@Autowired
	private IntelligenceInvestService intelligenceInvestService;

	@RabbitListener(queues = { RabbitConstant.Queue.INTELLIGENCE_INVEST_END })
	public void investEndEventSend(Long projectPackageInvestOrderId, Message message, Channel channel) throws IOException {
		log.info("智能投接收投资截发送信息订单ID{}", projectPackageInvestOrderId);
		try {
			intelligenceInvestService.sendInvestEndMsg(projectPackageInvestOrderId);
		} catch (Exception e) {
			log.warn("智能投接收投资截发送信息失败，订单ID{}，{}",projectPackageInvestOrderId,e.getMessage());
		} finally {
			channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
		}
	}
}
